package com.dslcode.cloud.common.utils;


import org.dozer.DozerBeanMapper;
import org.dozer.Mapper;

import java.util.ArrayList;
import java.util.List;


/**
 * 对象属性Util
 * @author 董思林
 * @date 2016年11月08日 15:55:30
 */
public class PropertyUtil<T> {

	private static final Mapper dozerMapper = new DozerBeanMapper();

	/**
	 * Dozer 复制属性，性能非常好
	 * @param source
	 * @param targetClass
	 * @return
	 */
	public static<T> T dozerMapper(Object source, Class<T> targetClass){
		if (null == source) return null;
		return dozerMapper.map(source, targetClass);
	}

	/**
	 * Dozer 复制List属性，性能非常好
	 * @param sources
	 * @param targetClass
	 * @return
	 */
	public static<T> List<T> dozerListMapper(List sources, Class<T> targetClass){
		if (null == sources) return null;
		int size = sources.size();
		if (size == 0) return new ArrayList<T>(0);
		List<T> results = new ArrayList<T>(sources.size());
		sources.forEach(s -> results.add(dozerMapper(s, targetClass)));
		return results;
	}

}
